package com.easy.controller;

import com.easy.bean.Attraction;
import com.easy.bean.User;
import com.easy.service.AttractionService;
import com.easy.service.UserService;
import com.easy.util.Page;
import com.easy.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin//允许跨域访问
@RequestMapping("/attraction")
public class AttractionController {
    @Autowired
    AttractionService attractionService;
    @PostMapping
    public Result add(@RequestBody Attraction attraction){
        Object obj = attractionService.add(attraction);
        return Result.success(obj);
    }

    @PutMapping
    public Result edit(@RequestBody Attraction attraction){
        Object obj = attractionService.edit(attraction);
        return Result.success(obj);
    }

    @DeleteMapping("/{id}")
    public Result del(@PathVariable("id") Integer id){
        Object obj = attractionService.del(id);
        return Result.success(obj);
    }

    @GetMapping("/{id}")
    public Result one(@PathVariable("id") Integer id){
        Object obj = attractionService.one(id);
        return Result.success(obj);
    }

    @GetMapping("all")
    public Result all(Attraction attraction){
        Object obj = attractionService.all(attraction);
        return Result.success(obj);
    }

    @GetMapping("page")
    public Result page(Page page, Attraction attraction){
        // 查询一共有多少条数据
        // 查询当前页要显示的数据
        // 将以上数据封装到 page 对象中
        // 返回 page 对象
        attractionService.page(page, attraction);
        return Result.success(page);
    }

}
